package com.finalist.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 随机数处理类
 * @author pengyb
 *
 */
public class RandomUtils
{
    /**
     * 获取某个区间类随机不重复的某几个数
     * @param scope 随机数范围
     * @param selectNum 所取随机数个数
     * @return 
     *        不重复随机数据集合
     */
    public static List<Integer> getRandomNum(Integer scope, Integer selectNum)
    {
        List<Integer> randomList = new ArrayList<Integer>();

        Random rand = new Random();
        boolean[] bool = new boolean[scope];
        int num = 0;
        for (int i = 0; i < selectNum; i++)
        {
            do
            {
                //如果产生的数相同继续循环  
                num = rand.nextInt(scope);
            }
            while (bool[num]);
            bool[num] = true;
            randomList.add(num);
        }
        return randomList;
    }

}
